package cn.itcast.service.impl;

import cn.itcast.dao.StandardDao;
import cn.itcast.domain.Standard;
import cn.itcast.service.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StandderServiceImpl implements StandardService {
    //注入Dao
    @Autowired
    private StandardDao standardDao;

    /**
     * 添加方法
     * @param standard
     */
    @Override
    @Transactional
    public void save(Standard standard) {
     standardDao.save(standard);
    }

    /**
     * 分页查询方法
     * @param page
     * @param rows
     * @return
     */
    @Override
    public Page<Standard> pageQuery(int page, int rows) {
        PageRequest pageRequest = PageRequest.of(page - 1, rows);
        return standardDao.findAll(pageRequest);
    }

    /**
     * 拓展的方法删除
     * @param ids
     */
    @Override
    public void batchDel(String[] ids) {
        for (String id : ids) {
            standardDao.deleteById(Integer.parseInt(id));
        }
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<Standard> courierfindAll() {
        return standardDao.findAll();
    }


}
